// home的模块小仓库

import {reqgetBaseCategoryList, reqgetBannerList, reqgetFloorList} from '@/api';

const state = {
    categoryList: [],
    bannerList: [],
    floorList: [],
};

const mutations = {
    CategoryList(state, categoryList){
        state.categoryList = categoryList;
    },

    BannerList(state, bannerList){
        state.bannerList = bannerList;
    },

    FloorList(state, floorList){
        state.floorList = floorList;
    },
};

const actions = {
    // 通过api接口调用，向服务器发送请求，获取数据
    // 参数{commit}!!!
    // 首页三级联动
    async categoryList({commit}){
        let result = await reqgetBaseCategoryList();
        // console.log("categoryList", result)
        if(result.code == 200){
            commit("CategoryList", result.data);
        }
    },

    // 轮播图
    async getBannerList({commit}){
        let result = await reqgetBannerList();
        // console.log("bannerList",result);
        if(result.code == 200){
            commit("BannerList", result.data);
        }
    },

    async getFloorList({commit}){
       let result = await reqgetFloorList();
    //    console.log("floorList",result);
       if(result.code == 200){
        commit("FloorList", result.data);
    }
    },
};

const getters = {};


export default {
    state,
    mutations,
    actions,
    getters
}
